package com.crayon.account.loader;

import android.content.Context;
import android.support.v4.content.AsyncTaskLoader;

import com.crayon.account.dao.DAOPhotos;
import com.crayon.account.dao.DataBaseManager;
import com.crayon.util.GDB;
import com.j256.ormlite.stmt.QueryBuilder;
import com.j256.ormlite.stmt.Where;

import java.util.LinkedList;
import java.util.List;

public class LoaderSQLPhotos extends AsyncTaskLoader<List<DAOPhotos>> {

	String query;
	public LoaderSQLPhotos(Context context,String query) {
		super(context);
		this.query=query;
	}

	@Override
	public List<DAOPhotos> loadInBackground() {

		DataBaseManager baseManager =DataBaseManager.getHelper(getContext());
		List<DAOPhotos> list =new LinkedList<DAOPhotos>();
		try {
			QueryBuilder<DAOPhotos, Integer> builder = baseManager.getDAOPhotos().queryBuilder().orderBy("dtStamp", false);
			Where<DAOPhotos, Integer> where = builder.where();
			where.isNotNull("arrays");
			list = where.query();
		}catch(Exception e ){
			GDB.log(getClass(), "result search err " + e.getMessage());
		}
		GDB.log(getClass(), "result " + (list==null ? 0 : list.size() )+":::");
		return list;
	}

	@Override
	protected void onStartLoading() {
		// TODO Auto-generated method stub
		super.onStartLoading();
		forceLoad();
	}

	public String getQuery() {
		return query;
	}

	public void setQuery(String query) {
		this.query = query;
	}

}


